package com.day11.study.thread_demo;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

class Type3Thread implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 0; i < 100; i++) {
            sum += i;
            System.out.println("--子线程" + sum);
        }
        return sum;
    }
}

public class Type3 {
    public static void main(String[] args) {
        FutureTask ft = new FutureTask(new Type3Thread());
        new Thread(ft).start();
        System.out.println("并行");
        Integer result = null;
        try {
            Thread.sleep(10);
            result = (Integer) ft.get();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("==主线程" + result);
    }
}
